package com.laoxu.test.sqlitedemo.controller;

import com.laoxu.test.sqlitedemo.mapper.AccountMapper;
import com.laoxu.test.sqlitedemo.model.AccountDO;
import com.laoxu.test.sqlitedemo.model.query.AccountQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author kalong
 * @date 2021/6/10
 */
@RestController
public class AccountController {

    @Autowired
    private AccountMapper accountMapper;

    @GetMapping("/queryById")
    public AccountDO selectByPrimaryKey(@RequestParam("id") Integer id) {
        AccountDO accountDO = accountMapper.selectByPrimaryKey(id);
        return accountDO;
    }

    @PostMapping("/query")
    public List<AccountDO> query(@RequestBody AccountQuery accountQuery) {
        List<AccountDO> accountDO = accountMapper.selectByQuery(accountQuery);
        return accountDO;
    }

    @PostMapping("/insert")
    public void insert(@RequestBody AccountDO record) {
        accountMapper.insert(record);
    }

}
